//
//  ScheduleViewController.m
//  项目三
//
//  Created by rimi on 15/9/28.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "ScheduleViewController.h"
#import "ZLNoSpacingFlowLayout.h"
#import "ZLCalenderCell.h"
#import "ZLRightCalender.h"
#import "ZLCalenderHeaderView.h"
#import "ZLCalenderView.h"
#import "Tool.h"

static NSString * const cellIdentifier = @"daycell";
static NSString * const headerIdentifier = @"headView";

@interface ScheduleViewController ()<UICollectionViewDelegateFlowLayout, ZLCalenderDelegate>
{
    Tool *_tool;
    NSUInteger _cellSide;
    NSUInteger _firstWeekdayInWeek;
    NSUInteger _days;
}

@property (nonatomic, strong) UITableView *tableview /**<  */;

@property (weak, nonatomic) IBOutlet UIImageView *bottonImage;
@property (nonatomic, strong) ZLCalenderView *calender /**< 日历 */;

- (void)initializeUserInterface; /**< 初始化用户界面 */

@end

@implementation ScheduleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
}

- (void)initializeUserInterface {
    [super initializeUserInterface];
    
    // 配置当天数据
    _tool = [Tool new];
    _firstWeekdayInWeek = [_tool getWeekOfFirstDayOfMonth:[_tool getYear] withMonth:[_tool getMonth]];
    _days = [_tool getDaysOfMonth:[_tool getYear] withMonth:[_tool getMonth]];
    
    // 导航栏初始化
    self.titleImageView.image = [UIImage imageNamed:@"图标-日程提醒_06"];
    [self.view addSubview:self.calender];
    [self.view addSubview:self.tableview];
}

- (void)reloadInputViews {
    [super reloadInputViews];
    _firstWeekdayInWeek = [_tool getWeekOfFirstDayOfMonth:[_tool getYear] withMonth:[_tool getMonth]];
    _days = [_tool getDaysOfMonth:[_tool getYear] withMonth:[_tool getMonth]];
}

#pragma mark - protocl
- (void)layoutCompliteWithHeight:(CGFloat)height {
    CGRect frame = _calender.frame;
    frame.origin.y += height;
    frame.size.width = CGRectGetWidth(frame);
    frame.size.height = CGRectGetMinY(self.bottonImage.frame) - CGRectGetMinY(frame) - 20;
    self.tableview.frame = frame;
}

#pragma mark - getter
- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(46, 0, 615, 500)) style:UITableViewStylePlain];
        UIImageView *bgImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"日历-1"]];
        
        _tableview.backgroundColor = [UIColor clearColor];
        _tableview.backgroundView = bgImageView;
    }
    return _tableview;
}

- (ZLCalenderView *)calender {
    if (!_calender) {
        _calender = [[ZLCalenderView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(35, 90, 632, 600))];
        _calender.days = _days;
        _calender.delegate = self;
        _calender.firstWeekdayInWeek = _firstWeekdayInWeek;
    }
    return _calender;
}

@end
